package com.ty.util;

import java.util.List;

/**
 * 分页类
 * @author Administrator
 *
 */
public class Pager {

	//每一页显示的条数
	private int pageSize=10;

	//记录当前页码数 
	private int currentPageIndex=1;
	
	//总条数
	private int totalCount=0;
	
	//总页数
	private int pages;
	
	//起始位置
	private int startRow;
	
	//记录当前分页的数据
	private List data;
	
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPageIndex() {
		return currentPageIndex;
	}

	//保证当前页面数是可以使用的范围
	public void setCurrentPageIndex(int currentPageIndex) {
		if(currentPageIndex<=0) { //小于当前范围的值
			this.currentPageIndex=1;
		}else if(currentPageIndex>getPages()) { //大于当前范围值
			this.currentPageIndex=getPages();
		}else {
			this.currentPageIndex = currentPageIndex; //在范围内
		}
		
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	//获取总页码数 
	public int getPages() {
		if(totalCount%pageSize==0) { //被整除
			this.pages=totalCount/pageSize; 
		}else { //不能被整除
			this.pages=(totalCount/pageSize)+1; 
		}
		return pages;
	}

	//计算出起始位置
	public int getStartRow() {
		this.startRow=(currentPageIndex-1)*pageSize;
		return startRow;
	}

	

	public List getData() {
		return data;
	}

	public void setData(List data) {
		this.data = data;
	}
}
